package Leetcode.StackAndQueue.maxSlidingWindow239;

import java.util.ArrayList;
import java.util.List;

/**
 * 暴力解法 时间复杂度为O(nk)
 */
public class Solution {
    public int[] maxSlidingWindow(int[] nums, int k) {
        int len = nums.length;
        if(len == 0) {
            return nums;
        }
        if(k == 0 || k == 1) {
            return nums;
        }
        List<Integer> result = new ArrayList();
        for(int i = 0; i <= len - k; i++) {
            int max = Integer.MIN_VALUE;
            for(int j = i; j < i + k && j < len; j++) {
                max = Math.max(max,nums[j]);
            }
            result.add(max);
        }
        int[] res = new int[result.size()];
        for(int i = 0; i < result.size(); i++) {
            res[i] = result.get(i);
        }

        return res;
    }

    public static void main(String[] args) {
        int[]  nums = {1,3,-1,-3,5,3,6,7};
        Solution solution = new Solution();
        int[] res = solution.maxSlidingWindow(nums, 3);
        for(int i : res) {
            System.out.print(i);
        }

    }
}
